import time
from django import template

register = template.Library()


@register.filter
def epoch(value):
    try:
        value = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(value)))
        return value
    except Exception as e:
        print(e)
        return '转换失败'


@register.filter
def sured(value):
    if value == "0":
        return "未确认"
    elif value == "1":
        return "已确认"
    else:
        return value


@register.filter
def severity(value):
    if value == "0":
        return "未分类"
    elif value == "1":
        return "信息"
    elif value == "2":
        return "警告"
    elif value == "3":
        return "一般严重"
    elif value == "4":
        return "严重"
    elif value == "5":
        return "灾难"
    else:
        return value
